package com.hadoop.mapreduce.mobilestatistics.bean;

import lombok.Builder;
import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author chenxigu
 */
@Data
public class MobileStatisticalData  implements WritableComparable<MobileStatisticalData> {
    /**
     * 手机号
     */
    private String mobile;
    /**
     * 上行流量
     */
    private Long upLinkTraffic;
    /**
     * 下行流量
     */
    private Long downLinkTraffic;
    /**
     * 总流量
     */
    private Long totalFlow;

    @Override
    public String toString() {
        return mobile+"\t"+upLinkTraffic+"\t"+downLinkTraffic+"\t"+totalFlow;
    }

    @Override
    public int compareTo(MobileStatisticalData o) {
        return totalFlow>o.getTotalFlow()?-1:1;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeBytes(mobile);
        out.writeLong(upLinkTraffic);
        out.writeLong(downLinkTraffic);
        out.writeLong(totalFlow);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        mobile=in.readUTF();
        upLinkTraffic = in.readLong();
        downLinkTraffic = in.readLong();
        totalFlow = in.readLong();
    }
}
